<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                template="/templates/template.xhtml">

    <ui:define name="title">余额记录</ui:define>
    <ui:define name="content">
        <h:form id="remainForm">
            <p:dialog header="操作执行中,请稍候" widgetVar="doing" modal="true" closable="false" resizable="false"
                      draggable="false"/>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:columnToggler datasource="statisticRecordDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         onstart="PF('doing').show()"
                                         update="@form"/>
                        <p:commandButton value="重置" actionListener="#{xhhSettlementRemainListBean.onReset()}"
                                         icon="fa fa-refresh"
                                         process="@this" update="@form"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         ajax="false">
                            <p:dataExporter type="xls" target="statisticRecordDataTable" fileName="余额记录"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-g ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12">
                    <div class="ui-g-12 card">
                        <h1>查询条件</h1>
                        <p:panelGrid columns="4" layout="grid"
                                     columnClasses="ui-grid-col-1,ui-grid-col-5,ui-grid-col-1,ui-grid-col-5"
                                     styleClass="ui-panelgrid-blank"
                                     style="border:0px none; background-color:transparent;text-align:center;">
                            <p:outputLabel value="主体名称"/>
                            <p:selectOneMenu id="productId" value="#{xhhSettlementRemainListBean.$.companyId}"
                                             filter="true" updateLabel="true"
                                             filterMatchMode="contains">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{xhhSettlementRemainListBean.companyList}"
                                               var="dic"
                                               itemLabel="#{dic.companyName}" itemValue="#{dic.id}"/>
                            </p:selectOneMenu>

                            <p:outputLabel value="创建日期"/>
                            <p:outputPanel>
                                <p:calendar
                                        id="startTime" styleClass="autoWidthCalendar"
                                        value="#{xhhSettlementRemainListBean.$.startTime}"
                                        locale="#{constants:get('LOCALE')}"
                                        timeZone="#{constants:get('TIME_ZONE')}"
                                        pattern="#{constants:get('DATE_FORMAT')}"/>
                                <span>— </span>
                                <p:calendar
                                        id="endTime" styleClass="autoWidthCalendar"
                                        value="#{xhhSettlementRemainListBean.$.endTime}"
                                        locale="#{constants:get('LOCALE')}"
                                        timeZone="#{constants:get('TIME_ZONE')}"
                                        pattern="#{constants:get('DATE_FORMAT')}"/>
                            </p:outputPanel>

                            <p:outputLabel value="记录类型"/>
                            <p:selectOneMenu id="remainType" value="#{xhhSettlementRemainListBean.$.remainType}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItem itemLabel="预付" itemValue="1"
                                              noSelectionOption="true"/>
                                <f:selectItem itemLabel="消耗" itemValue="2"
                                              noSelectionOption="true"/>
                            </p:selectOneMenu>
                        </p:panelGrid>
                    </div>

                    <div class="ui-g-12 card">
                        <p:dataTable id="statisticRecordDataTable"
                                     style="width: 100%;text-align:center"
                                     var="record"
                                     value="#{xhhSettlementRemainListBean.lazyDataModel}"
                                     rows="#{constants:get('ROWS')}"
                                     lazy="true"
                                     paginator="true"
                                     paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                     rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                     emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                     scrollable="true"
                                     scrollWidth="97%"
                                     reflow="true"
                                     selection=""
                                     resizableColumns="true">
                            <p:column headerText="操作" exportable="false" style="width: 150px">
                                <p:commandButton value="查看预付"
                                                 actionListener="#{xhhSettlementRemainListBean.onSeeRelateRecord(record.relateId,record.remainType)}"
                                                 icon="fa fa-eye"
                                                 process="@this" update="remainForm:prepay-dialog"
                                                 rendered="#{record.remainType==1}"
                                                 oncomplete="PF('prepay').show()"/>
                                <p:commandButton value="查看消耗"
                                                 actionListener="#{xhhSettlementRemainListBean.onSeeRelateRecord(record.relateId,record.remainType)}"
                                                 icon="fa fa-eye"
                                                 process="@this" update="remainForm:income-dialog"
                                                 rendered="#{record.remainType==2}"
                                                 oncomplete="PF('income').show()"/>
                            </p:column>
                            <p:column headerText="主体名称" style="width: 250px">
                                <h:outputText value="#{record.companyName}"/>
                            </p:column>
                            <p:column headerText="记录类型" style="text-align:center;width: 100px">
                                <h:outputText value="预付" rendered="#{record.remainType==1}"/>
                                <h:outputText value="消耗" rendered="#{record.remainType==2}"/>
                            </p:column>
                            <p:column headerText="预付前金额" style="text-align:center;width: 100px">
                                <h:outputText
                                        value="#{record.prePrepayAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="预付后金额" style="text-align:center;width: 100px">
                                <h:outputText
                                        value="#{record.prepayAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="消耗前金额" style="text-align:center;width: 100px">
                                <h:outputText
                                        value="#{record.preExpendAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="消耗后金额" style="text-align:center;width: 100px">
                                <h:outputText
                                        value="#{record.expendAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="剩余前金额" style="text-align:center;width: 100px">
                                <h:outputText
                                        value="#{record.preRemainAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="剩余后金额" style="text-align:center;width: 100px">
                                <h:outputText
                                        value="#{record.remainAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="创建人" style="text-align:center;width: 100px">
                                <h:outputText value="#{record.creator}"/>
                            </p:column>
                            <p:column headerText="创建时间" style="text-align:center;width: 150px">
                                <h:outputText value="#{record.createTime}">
                                    <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                </h:outputText>
                            </p:column>
                        </p:dataTable>
                    </div>
                </div>
            </div>


            <p:dialog header="预付记录" widgetVar="prepay" modal="true" closable="true" resizable="true" style="position: absolute;">
                <p:outputPanel id="prepay-dialog">
                    <div class="ui-g-12 ui-fluid" style="width:1000px;">
                        <p:panelGrid columns="4" layout="grid"
                                     columnClasses="ui-grid-col-1,ui-grid-col-5,ui-grid-col-1,ui-grid-col-5"
                                     styleClass="ui-panelgrid-blank"
                                     style="border:0px none; background-color:transparent;text-align:center;">
                            <p:outputLabel value="主体名称"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementPrepay.companyName}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="充值日期"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementPrepay.prepayTime}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}">
                                <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                            </p:inputText>

                            <p:outputLabel value="充值金额"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementPrepay.prepayAmount}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}">
                                <f:convertNumber pattern="#,##0.00"/>
                            </p:inputText>

                            <p:outputLabel value="付款方式"/>
                            <p:inputText
                                    value="#{xhhSettlementRemainListBean.translate(DictionaryCode.XHH_SETTLEMENT_PAY_MODE,xhhSettlementRemainListBean.settlementPrepay.payMode)}"
                                    disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel
                                    value="#{xhhSettlementRemainListBean.settlementPrepay.payMode == 1?'支付宝账户':'银行卡账户'}"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementPrepay.payName}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel
                                    value="#{xhhSettlementRemainListBean.settlementPrepay.payMode == 1?'支付宝账号':'银行卡账号'}"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementPrepay.payAccount}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}"/>
                        </p:panelGrid>

                        <p:panelGrid columns="2" layout="grid"
                                     columnClasses="ui-grid-col-1,ui-grid-col-11"
                                     styleClass="ui-panelgrid-blank"
                                     style="border:0px none; background-color:transparent;text-align:left;">
                            <p:outputLabel value="备注"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementPrepay.remark}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}"/>
                        </p:panelGrid>
                    </div>
                </p:outputPanel>
            </p:dialog>

            <p:dialog header="消耗记录" widgetVar="income" modal="true" closable="true"
                      resizable="true" style="position: absolute;">
                <p:outputPanel id="income-dialog">
                    <div class="ui-g-12 ui-fluid" style="width:1000px;">
                        <p:panelGrid columns="4" layout="grid"
                                     columnClasses="ui-grid-col-1,ui-grid-col-5,ui-grid-col-1,ui-grid-col-5"
                                     styleClass="ui-panelgrid-blank"
                                     style="border:0px none; background-color:transparent;text-align:center;">
                            <p:outputLabel value="产品名称"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.productName}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="主体名称"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.companyName}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="合作模式"/>
                            <p:inputText
                                    value="#{xhhSettlementRemainListBean.translate(DictionaryCode.XHH_COOPERATION_MODE,xhhSettlementRemainListBean.settlementIncome.copMode)}"
                                    disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="推广方式"/>
                            <p:inputText
                                    value="#{xhhSettlementRemainListBean.translate(DictionaryCode.XHH_SETTLEMENT_SPREAD_MODE,xhhSettlementRemainListBean.settlementIncome.spreadMode)}"
                                    disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="推广渠道"/>
                            <p:inputText
                                    value="#{xhhSettlementRemainListBean.translate(DictionaryCode.XHH_SETTLEMENT_SPREAD_CHANNEL,xhhSettlementRemainListBean.settlementIncome.spreadChannel)}"
                                    disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="结算模式"/>
                            <p:inputText
                                    value="#{xhhSettlementRemainListBean.translate(DictionaryCode.XHH_SETTLEMENT_CYCLE,xhhSettlementRemainListBean.settlementIncome.settlementMode)}"
                                    disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="收入类型"/>
                            <p:inputText
                                    value="#{xhhSettlementRemainListBean.translate(DictionaryCode.XHH_SETTLEMENT_INCOME_TYPE,xhhSettlementRemainListBean.settlementIncome.incomeType)}"
                                    disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="开始日期"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.startTime}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}">
                                <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                            </p:inputText>

                            <p:outputLabel value="结束日期"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.endTime}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}">
                                <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                            </p:inputText>
                        </p:panelGrid>

                        <p:outputPanel>
                            <p:panelGrid columns="4" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-5,ui-grid-col-1,ui-grid-col-5"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;text-align:center;">
                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==0
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==2
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==3}">
                                    <p:outputLabel value="结算价格（元）"/>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==0
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==2
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==3}">
                                    <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.priceCpa}"
                                                 disabled="#{xhhSettlementRemainListBean.isView()}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </p:inputText>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==1
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==3}">
                                    <p:outputLabel value="结算价格（%）"/>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==1
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==3}">
                                    <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.priceCps}"
                                                 disabled="#{xhhSettlementRemainListBean.isView()}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </p:inputText>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==0
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==3}">
                                    <p:outputLabel value="注册数"/>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==0
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==3}">
                                    <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.registerCount}"
                                                 disabled="#{xhhSettlementRemainListBean.isView()}"/>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==1
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==3}">
                                    <p:outputLabel value="放款金额"/>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==1
                                    || xhhSettlementRemainListBean.settlementIncome.copMode==3}">
                                    <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.lendAmount}"
                                                 disabled="#{xhhSettlementRemainListBean.isView()}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </p:inputText>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==2}">
                                    <p:outputLabel value="点击数"/>
                                </p:outputPanel>

                                <p:outputPanel rendered="#{xhhSettlementRemainListBean.settlementIncome.copMode==2}">
                                    <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.clickCount}"
                                                 disabled="#{xhhSettlementRemainListBean.isView()}"/>
                                </p:outputPanel>
                            </p:panelGrid>
                        </p:outputPanel>

                        <p:panelGrid columns="4" layout="grid"
                                     columnClasses="ui-grid-col-1,ui-grid-col-5,ui-grid-col-1,ui-grid-col-5"
                                     styleClass="ui-panelgrid-blank"
                                     style="border:0px none; background-color:transparent;text-align:center;">
                            <p:outputLabel value="结算金额"/>
                            <p:inputText id="incomeAmount"
                                         value="#{xhhSettlementRemainListBean.settlementIncome.incomeAmount}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}">
                                <f:convertNumber pattern="#,##0.00"/>
                            </p:inputText>
                        </p:panelGrid>

                        <p:panelGrid columns="2" layout="grid"
                                     columnClasses="ui-grid-col-1,ui-grid-col-11"
                                     styleClass="ui-panelgrid-blank"
                                     style="border:0px none; background-color:transparent;text-align:left;">
                            <p:outputLabel value="关联活动"/>
                            <p:chips id="advantageTag" value="#{xhhSettlementRemainListBean.activityNameList}"
                                     disabled="#{xhhSettlementRemainListBean.isView()}"/>

                            <p:outputLabel value="备注"/>
                            <p:inputText value="#{xhhSettlementRemainListBean.settlementIncome.remark}"
                                         disabled="#{xhhSettlementRemainListBean.isView()}"/>
                        </p:panelGrid>
                    </div>
                </p:outputPanel>
            </p:dialog>
        </h:form>
    </ui:define>
</ui:composition>